// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        nAddLabelCount : 0,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad : function () 
    {
        this.node.on('mousedown', function (event) 
        {
            cc.log("mousedown");
            // event.stopPropagation();
        }, this);
    },

    showWaitingLabel : function (str)
    {
        var waitingLabelNode = this.node.getChildByName('WaitingLabel');
        waitingLabelNode.stopAllActions();
        waitingLabelNode.oppacity = 0;
        waitingLabelNode.active = true;

        if (str != undefined)
        {
            var waitingLabel = waitingLabelNode.getComponent(cc.Label);
            waitingLabel.string = str;
        }

        var action1 = cc.fadeIn(0.5);
        var action2 = cc.delayTime(1.0);
        var action3 = cc.fadeOut(0.3);
        var action4 = cc.delayTime(1.0);
        var actionUnion = cc.repeatForever(cc.sequence(action1, action2, action3, action4));

        waitingLabelNode.runAction(actionUnion); 
    },

    addShowLabel : function (str)
    {
        // var newLabelNode = new cc.Node('label');
        // newLabelNode.addComponent(cc.Label);
        // this.node.addChild(newLabelNode);

        // var newLabel = newLabelNode.getComponent(cc.Label);
        // newLabel.string = str;
        // newLabel.scale = 10;

        var showLabelNode = this.node.getChildByName('ShowLabel');
        showLabelNode.stopAllActions();
        showLabelNode.oppacity = 0;
        showLabelNode.active = true;

        if (str != undefined)
        {
            var showLabel = showLabelNode.getComponent(cc.Label);
            showLabel.string = str;
        }
    },

    startCountDownTimer : function (countDownTime, countDownFuction)
    {
        this.countDonwSum = countDownTime;
        this.countDonwOverCallBack = countDownFuction;

        this.countDownCallBack = function () {
            if (this.countDonwSum > 0)
            {
                var node = new cc.Node("label");
                node.scale = 5;
                node.oppacity = 100;
                node.runAction

                var action1 = cc.fadeIn(0.3);
                var action2 = cc.delayTime(0.2);
                var action3 = cc.fadeOut(0.3);
                var action4 = cc.scaleTo(0.3, 1);

                var actionUnion1 = cc.spawn(action4, cc.sequence(action1, action2, action3));

                var label = node.addComponent(cc.Label);
                label.string = this.countDownSum.toString()

                node.runAction(actionUnion1);

                node.parent = this.node;
                this.countDonwSum--;
            }
            else
            {
                this.countDonwOverCallBack();
                this.unschedule(this.countDownCallBack);
            }
        };

        this.schedule(this.countDownCallBack, 1);

    },

    // start () {

    // },

    // update (dt) {},
});
